package cn.virens.database.common.mapper;

public class ExampleHaving {
	private String condition;
	private String type;

	private ExampleHaving(String condition) {
		this("AND", condition);
	}

	private ExampleHaving(String type, String condition) {
		this.condition = condition;
		this.type = type;
	}

	public String getType() {
		return type;
	}

	public String getCondition() {
		return condition;
	}

	public static ExampleHaving and(String condition) {
		return new ExampleHaving("AND", condition);
	}

	public static ExampleHaving or(String condition) {
		return new ExampleHaving("OR", condition);
	}

	public ExampleHaving addConditionWithAnd(String condition) {
		if (this.condition != null && !this.condition.isEmpty()) {
			this.condition = (this.condition + " AND " + condition);
		} else {
			this.condition = condition;
		}

		return this;
	}

	public ExampleHaving addConditionWithOr(String condition) {
		if (this.condition != null && !this.condition.isEmpty()) {
			this.condition = (this.condition + " OR " + condition);
		} else {
			this.condition = condition;
		}

		return this;
	}
}
